﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlScriptVault.Model
{
    [Serializable]
    public class Script
    {
        public Script(string fullPath, string scriptName)
        {
            FullPath = fullPath;
            ScriptName = scriptName;

            FileName = new FileInfo(FullPath).Name;
            ScriptContent = File.ReadAllText(FullPath);
        }

        public int Number { get; set; }
        public string ScriptName { get; set; }
        public string ScriptContent { get; set; }
        public List<string> ServerTypes { get; set; }

        public string FileName { get; private set; }
        public string FullPath { get; private set; }

        public string ServerTypesFormatted
        {
            get
            {
                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.Append("[");
                stringBuilder.Append(string.Join(", ", ServerTypes));
                stringBuilder.Append("] ");

                return stringBuilder.ToString();
            }
        }

        public override bool Equals(object obj)
        {
            if (!(obj is Script))
            {
                return false;
            }

            Script other = (Script)obj;

            return other.Number == Number;
        }

        public override int GetHashCode()
        {
            return Number.GetHashCode();
        }
    }
}
